﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

using WeifenLuo.WinFormsUI.Docking;

using ESRI.ArcGIS.Carto;
using ESRI.ArcGIS.Controls;
using ESRI.ArcGIS.esriSystem;
using ESRI.ArcGIS.Display;
using ESRI.ArcGIS.SystemUI;
using ESRI.ArcGIS.Geometry;
using ESRI.ArcGIS.Geodatabase;
using ESRI.ArcGIS.Output;
using ESRI.ArcGIS.DataSourcesGDB;
using ESRI.ArcGIS.ADF;
using ESRI.ArcGIS.Analyst3D;

namespace ClassroomAllocationAndManagementFrame
{
    public partial class FormForSceneControl : DockContent
    {
        public FormForSceneControl()
        {
            InitializeComponent();

            this.MouseWheel += new MouseEventHandler(FormForSceneControl_MouseWheel);
            NavigationCommand();
        }

        #region 滑轮事件
        void FormForSceneControl_MouseWheel(object sender, MouseEventArgs e)
        {
            try
            {
                System.Drawing.Point pSceLoc = this.axSceneControl1.PointToScreen(this.axSceneControl1.Location);
                System.Drawing.Point Pt = this.PointToScreen(e.Location);

                if (Pt.X < pSceLoc.X || Pt.X > pSceLoc.X + this.axSceneControl1.Width || Pt.Y < pSceLoc.Y || Pt.Y >
                    pSceLoc.Y + this.axSceneControl1.Height)
                {
                    return;
                }

                double scale = 0.2;
                if (e.Delta < 0)
                {
                    scale = -0.2;
                }

                ICamera pCamera = this.axSceneControl1.Camera;
                IPoint pPtObs = pCamera.Observer;
                IPoint pPtTar = pCamera.Target;

                pPtObs.X += (pPtObs.X - pPtTar.X) * scale;
                pPtObs.Y += (pPtObs.Y - pPtTar.Y) * scale;
                pPtObs.Z += (pPtObs.Z - pPtTar.Z) * scale;

                pCamera.Observer = pPtObs;
                this.axSceneControl1.SceneGraph.RefreshViewers();
            }
            catch
            {

            }
        }
        #endregion
        

        public void Destroy()
        {
            this.axSceneControl1.Dispose();
        }

        #region 定义一些Scene控件的事件
        public void LoadFile(string filePath)
        {
            try
            {
                this.axSceneControl1.LoadSxFile(filePath);
            }
            catch
            {
                MessageBox.Show("请重新导入！");
            }

        }

        public void FlyCommand()
        {
            ICommand command = new ControlsSceneFlyToolClass();
            command.OnCreate(this.axSceneControl1.Object);
            this.axSceneControl1.CurrentTool = command as ESRI.ArcGIS.SystemUI.ITool;
        }

        public void NavigationCommand()
        {
            ICommand command = new ControlsSceneNavigateToolClass();
            command.OnCreate(this.axSceneControl1.Object);
            this.axSceneControl1.CurrentTool = command as ESRI.ArcGIS.SystemUI.ITool;
        }

        public void ZoomInOutCommand()
        {
            ICommand command = new ControlsSceneZoomInOutToolClass();
            command.OnCreate(this.axSceneControl1.Object);
            this.axSceneControl1.CurrentTool = command as ESRI.ArcGIS.SystemUI.ITool;
        }

        public void ZoomInCommand()
        {
            ICommand command = new ControlsSceneZoomInToolClass();
            command.OnCreate(this.axSceneControl1.Object);
            this.axSceneControl1.CurrentTool = command as ESRI.ArcGIS.SystemUI.ITool;
        }

        public void ZoomOutCommand()
        {
            ICommand command = new ControlsSceneZoomOutToolClass();
            command.OnCreate(this.axSceneControl1.Object);
            this.axSceneControl1.CurrentTool = command as ESRI.ArcGIS.SystemUI.ITool;
        }

        public void NarrowViewCommand()
        {
            ICommand command = new ControlsSceneNarrowFOVCommandClass();
            command.OnCreate(this.axSceneControl1.Object);
            command.OnClick();
        }

        public void ExpandViewCommand()
        {
            ICommand command = new ControlsSceneExpandFOVCommandClass();
            command.OnCreate(this.axSceneControl1.Object);
            command.OnClick();
        }

        public void PanViewCommand()
        {
            ICommand command = new ControlsScenePanToolClass();
            command.OnCreate(this.axSceneControl1.Object);
            this.axSceneControl1.CurrentTool = command as ESRI.ArcGIS.SystemUI.ITool;
        }

        public void FullExtentCommand()
        {
            ICommand command = new ControlsSceneFullExtentCommandClass();
            command.OnCreate(this.axSceneControl1.Object);
            command.OnClick();
        }

        public void IdentityCommand()
        {
        }
        #endregion
    }
}
